package argo.hot100.stack;


public class MinStack {

    class ListNodeMin {
        public int val;
        public int minVal;
        public ListNodeMin next;

        public ListNodeMin(int x) {
            val = x;
            next = null;
        }

        public ListNodeMin(int x, int min) {
            val = x;
            minVal = min;
            next = null;
        }
    }

    ListNodeMin head;


    public MinStack() {
        head = null;
    }

    public void push(int val) {
        if (head == null) {
            head = new ListNodeMin(val, val);
        } else {
            ListNodeMin newNode = new ListNodeMin(val, Math.min(val, head.minVal));
            newNode.next = head;
            head = newNode;
        }
    }

    public void pop() {
        head = head.next;
    }

    public int top() {
        return head.val;
    }

    public int getMin() {
        return head.minVal;
    }


}
